package com.wosai.medical.hospital.demo.controller.check;

import com.google.common.collect.Lists;
import com.wosai.medical.hospital.demo.common.DataResult;
import com.wosai.medical.hospital.demo.controller.BaseController;
import com.wosai.medical.hospital.demo.controller.check.response.CheckReports;
import com.wosai.medical.hospital.demo.controller.check.response.CheckReportsDetail;
import com.wosai.medical.hospital.demo.controller.check.response.InspectReports;
import com.wosai.medical.hospital.demo.controller.check.response.InspectReportsDetail;
import com.wosai.medical.hospital.demo.controller.patient.response.FeeOrder;
import com.wosai.medical.hospital.demo.controller.patient.response.PendFees;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc
 * @auther 韦湘平
 * @date 2020/2/20 11:17 上午
 */

@Slf4j
@Api(tags = "检查报告")
@RestController
@RequestMapping("/hospital")
public class CheckController extends BaseController {


    /**
     * 5.1. 检查报告列表
     *
     * @param apiAppId   接入账号
     * @param apiVersion 接口版本号
     * @param apiStamp   时间戳
     * @param apiSign    参数签名
     * @param req
     * @return 候诊信息
     */
    @ApiOperation("5.1. 检查报告列表")
    @PostMapping("/check/reports")
    public RespResult<DataResult> getPendFee(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,

            @RequestBody(required = false) final Map<String, Serializable> req
    ) {
        return action(new Process<DataResult>() {
                          @Override
                          public String getAppId() {
                              return apiAppId;
                          }

                          @Override
                          public Integer getVersion() {
                              return apiVersion;
                          }

                          @Override
                          public Long getStamp() {
                              return apiStamp;
                          }

                          @Override
                          public String getSign() {
                              return apiSign;
                          }

                          @Override
                          public Map<String, Serializable> getParams() {
                              return req;
                          }

                          @Override
                          public DataResult handler() {
                              ///TODO: 业务处理
                              List<Serializable> checkReports = Lists.newArrayList(
                                      CheckReports.builder()
                                              .code("A11222")
                                              .name("刘德华")
                                              .type("ssss")
                                              .typeName("dssddssd")
                                              .order(CheckReports.Order.builder()
                                                      .dept(CheckReports.Dept.builder()
                                                              .code("dddd")
                                                              .name("到底是")
                                                              .build())
                                                      .doctor(CheckReports.Doctor.builder()
                                                              .code("dssddssd")
                                                              .name("zhannanshan")
                                                              .build())
                                                      .time("2020-03-09 20:09:09")
                                                      .build())
                                              .check(CheckReports.Check.builder()
                                                      .dept(CheckReports.Dept.builder()
                                                              .code("dddd")
                                                              .name("到底是")
                                                              .build())
                                                      .doctor(CheckReports.Doctor.builder()
                                                              .code("dssddssd")
                                                              .name("zhannanshan")
                                                              .build())
                                                      .time("2020-03-09 20:09:09")
                                                      .build())
                                              .status(1)
                                              .time("2020-03-09 20:09:09")
                                              .build()
                              );
                              return DataResult.builder().totals(1L).rows(checkReports).build();
                          }
                      }
        );
    }

    /**
     * 5.2. 检查报告明细
     *
     * @param apiAppId        接入账号
     * @param apiVersion      接口版本号
     * @param apiStamp        时间戳
     * @param apiSign         参数签名
     * @param checkReportCode 检查报告代码(唯一标识)
     * @return 获取患者信息
     */
    @ApiOperation("5.2. 检查报告明细")
    @GetMapping("/check/report/{checkReportCode}")
    public RespResult<CheckReportsDetail> getPatientInfo(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,
            //检查报告代码(唯一标识)
            @PathVariable final String checkReportCode
    ) {
        return action(new Process<CheckReportsDetail>() {
            @Override
            public String getAppId() {
                return apiAppId;
            }

            @Override
            public Integer getVersion() {
                return apiVersion;
            }

            @Override
            public Long getStamp() {
                return apiStamp;
            }

            @Override
            public String getSign() {
                return apiSign;
            }

            @Override
            public Map<String, Serializable> getParams() {
                return new HashMap<String, Serializable>(2) {
                    {
                        put("checkReportCode", checkReportCode);
                    }
                };
            }

            @Override
            public CheckReportsDetail handler() {
                ///TODO: 业务处理
                return CheckReportsDetail.builder()
                        .code("A112222")
                        .name("刘德华")
                        .parts("head")
                        .situation("aa")
                        .diagnosis("dddd")
                        .build();
            }
        });
    }

    /**
     * 5.3. 检验报告列表
     *
     * @param apiAppId   接入账号
     * @param apiVersion 接口版本号
     * @param apiStamp   时间戳
     * @param apiSign    参数签名
     * @param req
     * @return 候诊信息
     */
    @ApiOperation("5.3. 检验报告列表")
    @PostMapping("/inspect/reports")
    public RespResult<DataResult> getinspectreports(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,

            @RequestBody(required = false) final Map<String, Serializable> req
    ) {
        return action(new Process<DataResult>() {
                          @Override
                          public String getAppId() {
                              return apiAppId;
                          }

                          @Override
                          public Integer getVersion() {
                              return apiVersion;
                          }

                          @Override
                          public Long getStamp() {
                              return apiStamp;
                          }

                          @Override
                          public String getSign() {
                              return apiSign;
                          }

                          @Override
                          public Map<String, Serializable> getParams() {
                              return req;
                          }

                          @Override
                          public DataResult handler() {
                              ///TODO: 业务处理
                              List<Serializable> inspectReports = Lists.newArrayList(
                                      InspectReports.builder()
                                              .code("A11222")
                                              .name("ct")
                                              .order(InspectReports.Order.builder()
                                                      .dept(InspectReports.Dept.builder()
                                                              .code("dddd")
                                                              .name("到底是")
                                                              .build())
                                                      .doctor(InspectReports.Doctor.builder()
                                                              .code("dssddssd")
                                                              .name("zhannanshan")
                                                              .build())
                                                      .time("2020-03-09 20:09:09")
                                                      .build())
                                              .inspect(InspectReports.Inspect.builder()
                                                      .dept(InspectReports.Dept.builder()
                                                              .code("dddd")
                                                              .name("到底是")
                                                              .build())
                                                      .doctor(InspectReports.Doctor.builder()
                                                              .code("dssddssd")
                                                              .name("zhannanshan")
                                                              .build())
                                                      .time("2020-03-09 20:09:09")
                                                      .build())
                                              .verify(InspectReports.Verify.builder()
                                                      .doctor(InspectReports.Doctor.builder()
                                                              .code("dssddssd")
                                                              .name("zhannanshan")
                                                              .build())
                                                      .time("2020-03-09 20:09:09")
                                                      .build())
                                              .status(1)
                                              .time("2020-03-09 20:09:09")
                                              .build()
                              );
                              return DataResult.builder().totals(1L).rows(inspectReports).build();
                          }
                      }
        );
    }

    /**
     * 5.4. 检验报告明细
     *
     * @param apiAppId          接入账号
     * @param apiVersion        接口版本号
     * @param apiStamp          时间戳
     * @param apiSign           参数签名
     * @param inspectReportCode 检验报告代码(唯一标识)
     * @return 获取患者信息
     */
    @ApiOperation("5.4. 检验报告明细\n")
    @GetMapping("/inspect/report/{inspectReportCode}")
    public RespResult<DataResult> getinspectReport(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,
            //检验报告代码(唯一标识)
            @PathVariable final String inspectReportCode
    ) {
        return action(new Process<DataResult>() {
            @Override
            public String getAppId() {
                return apiAppId;
            }

            @Override
            public Integer getVersion() {
                return apiVersion;
            }

            @Override
            public Long getStamp() {
                return apiStamp;
            }

            @Override
            public String getSign() {
                return apiSign;
            }

            @Override
            public Map<String, Serializable> getParams() {
                return new HashMap<String, Serializable>(2) {
                    {
                        put("inspectReportCode", inspectReportCode);
                    }
                };
            }

            @Override
            public DataResult handler() {
                ///TODO: 业务处理
                List<Serializable> inspectReportsDetails = Lists.newArrayList(
                        InspectReportsDetail.builder()
                                .name("xiongtou")
                                .result("ok")
                                .unit("单位")
                                .range("1-100")
                                .abnormal(0)
                                .microbials(Lists.newArrayList(
                                        InspectReportsDetail.Microbial.builder()
                                                .name("ssss")
                                                .bacterialCount(100)
                                                .antibioticsName("ddds")
                                                .result("ok")
                                                .unit("a/dd")
                                                .range("0-100")
                                                .method("sss")
                                                .note("ok")
                                                .build()
                                ))
                                .build()
                );

                return DataResult.builder().totals(1L).rows(inspectReportsDetails).build();
            }
        });
    }

}